package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ColorPicker;
import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

/**
 * @ClassName ColorPickerDemo
 * @Description
 * @Author wangss
 * @date 2020.05.26 09:42
 * @Version 1.0
 */
public class ColorPickerDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        ColorPicker cp = new ColorPicker(Color.valueOf("#FFF"));

        anchorPane.getChildren().add(cp);

        primaryStage.setScene(scene);
        primaryStage.setTitle("combobox");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        cp.valueProperty().addListener((observable, oldValue, newValue) -> {
            System.out.println("red = " + newValue.getRed());
            System.out.println("green = " + newValue.getGreen());
            System.out.println("blue = " + newValue.getBlue());

            System.out.println("rgb = " + newValue.toString());
            String color = newValue.toString().substring(2);

            anchorPane.setStyle("-fx-background-color: #" + color + ";");
        });
    }
}
